package launcher;

import java.awt.Desktop;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import javax.swing.DefaultListModel;


public class launcher extends javax.swing.JFrame {


    /*
     * Die Methode erstellt das GUI
     * Wenn die config.jsl nicht existiert wird sie durch speichern erzeugt
     * Wenn sie existiert wird die les- und beschreibbar gesetzt und geladen
     */
    public launcher() {
        initComponents();
        if(!Save.exists()){ 
            Speichern(); 
        }
        Save.setReadable(true,false); 
        Save.setWritable(true, false); 
        Laden(); 
    }


    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        Fehler = new javax.swing.JDialog();
        Fehlertext = new javax.swing.JLabel();
        FehlerClose = new javax.swing.JButton();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel3 = new javax.swing.JPanel();
        CacheLeeren = new javax.swing.JButton();
        WoWStart = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        jTabbedPane2 = new javax.swing.JTabbedPane();
        WoWPfadWählen = new javax.swing.JFileChooser();
        jPanel4 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        ListeSprache = new javax.swing.JList();
        SpracheWählen = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        jScrollPane3 = new javax.swing.JScrollPane();
        favo_rl = new javax.swing.JList();
        rl_eingabe = new javax.swing.JTextField();
        rl_add = new javax.swing.JButton();
        rl_change = new javax.swing.JButton();
        rl_del = new javax.swing.JButton();

        Fehler.setTitle("Fehlermeldung");
        Fehler.setAlwaysOnTop(true);
        Fehler.setMinimumSize(new java.awt.Dimension(400, 116));

        Fehlertext.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        Fehlertext.setText("Fehlertext");

        FehlerClose.setText("Okay");
        FehlerClose.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                FehlerCloseActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout FehlerLayout = new javax.swing.GroupLayout(Fehler.getContentPane());
        Fehler.getContentPane().setLayout(FehlerLayout);
        FehlerLayout.setHorizontalGroup(
            FehlerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(FehlerLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(FehlerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(FehlerLayout.createSequentialGroup()
                        .addComponent(Fehlertext, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addContainerGap())
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, FehlerLayout.createSequentialGroup()
                        .addGap(0, 135, Short.MAX_VALUE)
                        .addComponent(FehlerClose, javax.swing.GroupLayout.PREFERRED_SIZE, 112, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(143, 143, 143))))
        );
        FehlerLayout.setVerticalGroup(
            FehlerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(FehlerLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(Fehlertext)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 57, Short.MAX_VALUE)
                .addComponent(FehlerClose)
                .addContainerGap())
        );

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("WoW Launcher - DarkSource");
        setMinimumSize(new java.awt.Dimension(628, 275));
        setResizable(false);

        CacheLeeren.setText("Cache leeren");
        CacheLeeren.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                CacheLeerenActionPerformed(evt);
            }
        });

        WoWStart.setFont(new java.awt.Font("Arial", 1, 14)); // NOI18N
        WoWStart.setText("Start WoW");
        WoWStart.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                WoWStartActionPerformed(evt);
            }
        });

        jLabel2.setText("© Darkor | darksource.de");

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jLabel2))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGap(314, 314, 314)
                        .addComponent(CacheLeeren, javax.swing.GroupLayout.PREFERRED_SIZE, 146, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(WoWStart, javax.swing.GroupLayout.PREFERRED_SIZE, 167, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 2, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap(312, Short.MAX_VALUE)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel2, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(CacheLeeren, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(WoWStart, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(55, 55, 55))))
        );

        jTabbedPane1.addTab("Launcher", jPanel3);

        jPanel2.setPreferredSize(new java.awt.Dimension(623, 355));

        WoWPfadWählen.setApproveButtonText("Auswählen");
        WoWPfadWählen.setCurrentDirectory(new java.io.File("C:\\"));
            WoWPfadWählen.setDialogTitle("");
            WoWPfadWählen.setFileSelectionMode(javax.swing.JFileChooser.DIRECTORIES_ONLY);
            WoWPfadWählen.setPreferredSize(new java.awt.Dimension(603, 355));
            WoWPfadWählen.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    WoWPfadWählenActionPerformed(evt);
                }
            });
            jTabbedPane2.addTab("WoW Pfad", WoWPfadWählen);

            ListeSprache.setModel(new javax.swing.AbstractListModel() {
                String[] strings = { "deDE", "enGB", "enUS" };
                public int getSize() { return strings.length; }
                public Object getElementAt(int i) { return strings[i]; }
            });
            ListeSprache.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
            jScrollPane2.setViewportView(ListeSprache);

            SpracheWählen.setText("Wählen");
            SpracheWählen.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    SpracheWählenActionPerformed(evt);
                }
            });

            javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
            jPanel4.setLayout(jPanel4Layout);
            jPanel4Layout.setHorizontalGroup(
                jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel4Layout.createSequentialGroup()
                    .addContainerGap()
                    .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addComponent(jScrollPane2)
                        .addComponent(SpracheWählen, javax.swing.GroupLayout.DEFAULT_SIZE, 125, Short.MAX_VALUE))
                    .addContainerGap(505, Short.MAX_VALUE))
            );
            jPanel4Layout.setVerticalGroup(
                jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel4Layout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(SpracheWählen)
                    .addContainerGap(224, Short.MAX_VALUE))
            );

            jTabbedPane2.addTab("Sprache", jPanel4);

            javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
            jPanel2.setLayout(jPanel2Layout);
            jPanel2Layout.setHorizontalGroup(
                jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(jTabbedPane2)
            );
            jPanel2Layout.setVerticalGroup(
                jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(jTabbedPane2, javax.swing.GroupLayout.Alignment.TRAILING)
            );

            jTabbedPane1.addTab("Optionen", jPanel2);

            jScrollPane3.setViewportView(favo_rl);

            rl_add.setText("Hinzufügen");
            rl_add.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    rl_addActionPerformed(evt);
                }
            });

            rl_change.setText("Ändern");
            rl_change.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    rl_changeActionPerformed(evt);
                }
            });

            rl_del.setText("Entfernen");
            rl_del.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    rl_delActionPerformed(evt);
                }
            });

            javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
            jPanel1.setLayout(jPanel1Layout);
            jPanel1Layout.setHorizontalGroup(
                jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 132, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(rl_eingabe, javax.swing.GroupLayout.PREFERRED_SIZE, 172, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGroup(jPanel1Layout.createSequentialGroup()
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                .addComponent(rl_del, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(rl_add, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(rl_change, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addContainerGap(321, Short.MAX_VALUE))
            );
            jPanel1Layout.setVerticalGroup(
                jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createSequentialGroup()
                    .addContainerGap()
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel1Layout.createSequentialGroup()
                            .addComponent(rl_eingabe, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(rl_add)
                                .addComponent(rl_change))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(rl_del)
                            .addGap(0, 0, Short.MAX_VALUE))
                        .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE))
                    .addContainerGap())
            );

            jTabbedPane1.addTab("Realmlisten", jPanel1);

            javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(jTabbedPane1)
            );
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(jTabbedPane1)
            );

            pack();
        }// </editor-fold>//GEN-END:initComponents

    private void FehlerCloseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_FehlerCloseActionPerformed
        Fehler.setVisible(false);
        Fehler.setTitle("Fehler");
    }//GEN-LAST:event_FehlerCloseActionPerformed

    private void rl_delActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rl_delActionPerformed
        int k = favo_rl.getSelectedIndex();
        DefaultListModel favo = (DefaultListModel) favo_rl.getModel();
        favo.remove(k);
        Speichern();
        Laden();
    }//GEN-LAST:event_rl_delActionPerformed

    private void rl_changeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rl_changeActionPerformed
        File Realmliste = new File(WoWPfad.toString() + "/Data/" + Sprache + "/realmlist.wtf");
        try (FileOutputStream Set = new FileOutputStream(Realmliste)) {
            if (favo_rl.isSelectionEmpty()) {
                Set.write(("set realmlist " + rl_eingabe.getText()).getBytes());
            } else {
                Set.write(("set realmlist " + favo_rl.getSelectedValue().toString()).getBytes());
            }
            Set.flush();
        } catch (Exception e) {
            Fehlertext.setText(e.toString());
            Fehler.setVisible(true);
        }
        Fehlertext.setText("Realmlist erfolgreich geändert.");
        Fehler.setTitle("Realmlist geändert");
        Fehler.setVisible(true);
    }//GEN-LAST:event_rl_changeActionPerformed

    private void rl_addActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rl_addActionPerformed
        try {
            DefaultListModel Favs = (DefaultListModel) favo_rl.getModel();
            Favs.addElement(rl_eingabe.getText());
            Speichern();
            Laden();
        } catch (Exception e) {
            Fehlertext.setText(e.toString());
            Fehler.setVisible(true);
        }
    }//GEN-LAST:event_rl_addActionPerformed

    private void SpracheWählenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SpracheWählenActionPerformed
        File e = new File(WoWPfad.toString() + "/Data/" + ListeSprache.getSelectedValue().toString());
        if (e.exists()) {
            Sprache = ListeSprache.getSelectedValue().toString();
            Speichern();
        } else {
            Fehlertext.setText("Dieses Sprachpacket ist nicht vorhanden!");
            Fehler.setVisible(true);
        }
    }//GEN-LAST:event_SpracheWählenActionPerformed

    private void WoWPfadWählenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_WoWPfadWählenActionPerformed
        File e = new File(WoWPfadWählen.getSelectedFile().toString() + "/wow.exe");
        File d = new File(WoWPfadWählen.getSelectedFile().toString()+ "/WoW.exe");
        if (e.exists() || d.exists()) {
            WoWPfad = WoWPfadWählen.getSelectedFile();
            Speichern();
        } else {
            Fehlertext.setText("Dieses Verzeichniss enthält keine wow.exe!");
            Fehler.setVisible(true);
        }
    }//GEN-LAST:event_WoWPfadWählenActionPerformed

    private void WoWStartActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_WoWStartActionPerformed
        WoWStart();
    }//GEN-LAST:event_WoWStartActionPerformed

    private void CacheLeerenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CacheLeerenActionPerformed
        CacheLeeren();
    }//GEN-LAST:event_CacheLeerenActionPerformed


    public static void main(String args[]) {

        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /*
         * If Nimbus (introduced in Java SE 6) is not available, stay with the
         * default look and feel. For details see
         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Windows".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(launcher.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        java.awt.EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {
                new launcher().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton CacheLeeren;
    private javax.swing.JDialog Fehler;
    private javax.swing.JButton FehlerClose;
    private javax.swing.JLabel Fehlertext;
    private javax.swing.JList ListeSprache;
    private javax.swing.JButton SpracheWählen;
    private javax.swing.JFileChooser WoWPfadWählen;
    private javax.swing.JButton WoWStart;
    private javax.swing.JList favo_rl;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JTabbedPane jTabbedPane2;
    private javax.swing.JButton rl_add;
    private javax.swing.JButton rl_change;
    private javax.swing.JButton rl_del;
    private javax.swing.JTextField rl_eingabe;
    // End of variables declaration//GEN-END:variables
// Eigene Variablen
    private File WoWPfad = new File("Neue Datei");
    private File Save = new File(System.getProperty("user.dir")+"/config.jsl");
    private String Sprache;
    
    
  //Eigene Methoden
    
    /*
     * Die Methode sucht alle .wdb Files im Pfad und löscht diese
     * Anschließend wird eine Meldung an den Benutzer zurück gegeben
     * Debugging Meldungen über System.out.println()
     */
    private void CacheLeeren(){
        File WDB = new File(WoWPfad.toString()+"/Cache/WDB/"+Sprache+"/");
        System.out.println(WDB.toString());
        for(File file : WDB.listFiles()){
            if(file.toString().endsWith(".wdb")){
                System.out.println(file.toString()+"gelöscht"+file.delete());
                }
            }
        Fehlertext.setText("Cache erfolgreich geleert!");
        Fehler.setTitle("Cache geleert");
        Fehler.setVisible(true);
        }
    
    /*
     * Die Methode wählt die wow.exe und startet diese
     * Fehlermeldungen werden dem Benutzer mitgeteilt
     * Debugging Meldungen über System.out.println()
     */
    private void WoWStart(){
        File WoW = new File(WoWPfad.toString()+"/wow.exe");
        if(!WoW.exists()){
            WoW = new File(WoWPfad.toString()+"/WoW.exe");
        }
        System.out.println(WoW.toString());
        try{
            Runtime.getRuntime().exec(WoW.toString());
        }catch(Exception e){
            Fehlertext.setText(e.toString());
            System.out.println(e.toString());
            Fehler.setVisible(true);
        }
    }
    
    /*
     * Die Methode speichert folgende Werte in der config.jsl Datei ab:
     * WoWPfad
     * Sprache
     * Alle Realmlisten
     * Fehlermeldungen werden dem Benutzer mitgeteilt
     * Debugging Meldungen über System.out.println()
     */
    private void Speichern(){
            try (FileOutputStream Saver = new FileOutputStream(Save)) {
                System.out.println(Save.toString());
                Saver.write("--WoWPfad--\n".getBytes());
                Saver.write((WoWPfad.toString()+"\n").getBytes());
                System.out.println("WOW Pfad gespeichert");
                Saver.write("--Sprache--\n".getBytes());
                Saver.write((Sprache+"\n").getBytes());
                System.out.println("Sprache gespeichert");
                Saver.write("--Realmlisten--\n".getBytes());
                int g = favo_rl.getModel().getSize();
                for(int i = 0; i < g;i++){
                    Saver.write((favo_rl.getModel().getElementAt(i).toString()+"\n").getBytes());
                }
                System.out.println("Realmlisten gespeichert");
        }catch(Exception e){
            Fehlertext.setText(e.toString());
            System.out.println(e.toString());
            Fehler.setVisible(true);
        }        
    }
    
    /*
     * Die Methode lädt folgende Werte aus der config.jsl Datei:
     * WoWPfad
     * Sprache
     * Alle Realmlisten
     * Fehlermeldungen werden dem Benutzer mitgeteilt
     * Debugging Meldungen über System.out.println()
     */
    private void Laden(){
        try{
            try (BufferedReader Set = new BufferedReader(new java.io.FileReader(Save))) {
                if(Set.readLine().equalsIgnoreCase("--WoWPfad--")){
                    WoWPfad = new File(Set.readLine());
                }
                System.out.println("WoWPfad geladen");
                if(Set.readLine().equalsIgnoreCase("--Sprache--")){
                    Sprache = Set.readLine();
                }
                System.out.println("Sprache geladen");
                if(Set.readLine().equalsIgnoreCase("--Realmlisten--")){
                    DefaultListModel favs = new DefaultListModel();
                    String e = Set.readLine();
                    while(e != null){
                        favs.addElement(e);
                        e = Set.readLine();
                    }
                     favo_rl.setModel(favs);
                }
                System.out.println("Realmlisten geladen");
            }
        }catch(Exception d){
            Fehlertext.setText(d.toString());
            System.out.println(d.toString());
            Fehler.setVisible(true);
        }
    }

}
